package com.hr.reactive.operators;


import com.hr.reactive.common.Utils;
import org.checkerframework.checker.units.qual.C;
import reactor.core.publisher.Flux;

import java.util.function.Function;
import java.util.function.UnaryOperator;

/**
 * @author Administrator
 */
public class Lec08Transform {
    record Customer(int id,String name){

    }
    record PurchaseOrder(String productName,int price,int quantity){}
    public static void main(String[] args) {
        var isDebug=true;
        getCustomer()
                .transform(isDebug?addDebugger(): Function.identity())
                .subscribe();

        getOrder().transform(addDebugger())

                .subscribe();
    }
    private static Flux<Customer> getCustomer(){
        return Flux.range(1,3)
                .map(i->new Customer(i, Utils.faker().name().firstName()));
    }
    private static Flux<PurchaseOrder> getOrder(){
        return Flux.range(1,5)
                .map(i->new PurchaseOrder(Utils.faker().commerce().productName(), i,i*10));
    }
    private static <T>UnaryOperator<Flux<T>> addDebugger(){
        return flux->flux .doOnNext(i-> System.out.println(i))
                .doOnComplete(()-> System.out.println("doOnComplete"))
                .doOnError(err-> System.out.println(err));
    }
}
